﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

[System.Serializable]
public struct SyncVector3
{
    public readonly static SyncVector3 Zero=new SyncVector3(0,0,0);
    public int x;
    public int y;
    public int z;
    public SyncVector3(int x, int y, int z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Vector3 ToVector3()
    {
        return new Vector3(x*0.001f,y*0.001f,z*0.001f);
    }

    public SyncVector3 FromVector3(Vector3 from)
    {
        x = (int) (from.x * 1000);
        y = (int)(from.y * 1000);
        z = (int)(from.z * 1000);

        return this;
    }

    public SyncVector3 DeepCopy()
    {
        SyncVector3 copy=new SyncVector3(x,y,z);
        return copy;
    }

    public bool Equals(SyncVector3 go)
    {
        if (go.x !=x)
        {
            return false;
        }

        if (go.y != y)
        {
            return false;
        }
        if (go.z != z)
        {
            return false;
        }

        return true;
    }

    public bool Equals(Vector3 go)
    {
        Vector3 bi = this.ToVector3();
        if (bi.x !=go.x)
        {
            return false;
        }
        if (bi.y != go.y)
        {
            return false;
        }
        if (bi.z != go.z)
        {
            return false;
        }

        return true;
    }

    public override string ToString()
    {
        return "SyncVector3(" + x + "," + y + "," + z + ")";
    }
     
    #region +
    public static SyncVector3 operator +(SyncVector3 a, SyncVector3 b)
    {
        SyncVector3 result = new SyncVector3(a.x + b.x, a.y + b.y, a.z + b.z);
        return result;
    }
    public static SyncVector3 operator +(SyncVector3 a, int b)
    {
        SyncVector3 result = new SyncVector3(a.x + b, a.y + b, a.z + b);
        return result;
    }
    public static SyncVector3 operator +(SyncVector3 a, float b)
    {
        SyncVector3 result = new SyncVector3((int)(a.x + b), (int)(a.y + b), (int)(a.z + b));
        return result;
    }


    #endregion

    #region -
    public static SyncVector3 operator -(SyncVector3 a, SyncVector3 b)
    {
        SyncVector3 result = new SyncVector3(a.x - b.x, a.y - b.y, a.z - b.z);
        return result;
    }
    public static SyncVector3 operator -(SyncVector3 a, int b)
    {
        SyncVector3 result = new SyncVector3(a.x - b, a.y - b, a.z - b);
        return result;
    }
    public static SyncVector3 operator -(SyncVector3 a, float b)
    {
        SyncVector3 result = new SyncVector3((int)(a.x - b), (int)(a.y - b), (int)(a.z - b));
        return result;
    }


    #endregion

    #region *
    public static SyncVector3 operator *(SyncVector3 a, SyncVector3 b)
    {
        SyncVector3 result = new SyncVector3(a.x * b.x / 1000, a.y * b.y / 1000, a.z * b.z / 1000);
        return result;
    }
    public static SyncVector3 operator *(SyncVector3 a, int b)
    {
        SyncVector3 result = new SyncVector3(a.x * b, a.y * b, a.z * b);
        return result;
    }


    #endregion

    #region /
    public static SyncVector3 operator /(SyncVector3 a, SyncVector3 b)
    {
        SyncVector3 result = new SyncVector3(a.x / b.x * 1000, a.y / b.y * 1000, a.z / b.z * 1000);
        return result;
    }
    public static SyncVector3 operator /(SyncVector3 a, int b)
    {
        SyncVector3 result = new SyncVector3(a.x / b, a.y / b, a.z / b);
        return result;
    }
    public static SyncVector3 operator /(SyncVector3 a, float b)
    {
        SyncVector3 result = new SyncVector3((int)(a.x / b), (int)(a.y / b), (int)(a.z / b));
        return result;
    }


    #endregion

    #region ==

    public static bool operator ==(SyncVector3 a, SyncVector3 b)
    {
        if (a.x != b.x)
        {
            return false;
        }
        if (a.y != b.y)
        {
            return false;
        }
        if (a.z != b.z)
        {
            return false;
        }

        return true;
    }
    public static bool operator !=(SyncVector3 a, SyncVector3 b)
    {
        if (a.x != b.x)
        {
            return true;
        }
        if (a.y != b.y)
        {
            return true;
        }
        if (a.z != b.z)
        {
            return true;
        }

        return false;
    }

    public override bool Equals(object obj)
    {
        if (obj is SyncVector3)
        {
            return this == (SyncVector3)obj;
        }

        return false;
    }

    #endregion



    public override int GetHashCode()
    {
        return base.GetHashCode();
    }
}
